var setting={
autoLogin:0,
setVpn:function(ip,passport,password){
    var param={
    ip:ip,
    passport:passport,
    password:password
    };
    vpn.openVpn(function(su){
                var uri="http://19.131.100.224:8080/zhcx/gov.sscz.zhsp.touch.view.Main.d?user="+passport+"&version=ios_"+su;
                uri=decodeURIComponent(uri);
                window.location.href=uri;
                //window.location.href="http://www.baidu.com";
                },
                function(er){
                $.AMUI.progress.done();
                $('#loginTip p:first').text("登录异常，请重新登录");
                $('#loginTip').show();
                $('#loginTip').delay(6000).hide(0);
                },param);
},
closeVpn:function(){
    vpn.closeVpn(function(su){alert("成功关闭");},function(er){
                 alert("关闭失败");
                 });
},
changePwd:function(oldPwd,newPwd){
    var param={
    newPwd:newPwd,
    oldPwd:oldPwd
    };
    vpn.changePwd(function(su){alert("密码修改成功");},function(er){
                  alert("密码修改失败");
                  },param);
},
openPage:function(path){
    var param={
        path:path
    };
    vpn.openPage(function(su){},function(er){},param);
},
closePage:function(){
    var param={};
    vpn.closePage(function(su){},function(er){},param);
},
    // Application Constructor
initialize: function (autoLogin) {
    if(autoLogin)
        this.autoLogin=autoLogin;
    this.bindEvents();
},
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function () {
    document.addEventListener('deviceready', this.onDeviceReady, false);
},
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function () {
    setting.receivedEvent('deviceready');
},
    // Update DOM on a Received Event
receivedEvent: function (id) {
    var vpnCookie = localStorage.VPN_REMEMBER_ME_COOKIE_;
    if(vpnCookie){
        vpnCookie=JSON.parse(vpnCookie);
        $('#ip').val(vpnCookie.ip);
        $('#name').val(vpnCookie.name);
        $('#pass').val(vpnCookie.pass);
        
        if(this.autoLogin==0&&false) {
            $.AMUI.progress.start();
            setting.setVpn(vpnCookie.ip, vpnCookie.name, vpnCookie.pass);
        }
    }
},
getQueryStringByName:function(name){
    var result = location.search.match(new RegExp("[\?\&]" + name+ "=([^\&]+)","i"));
    if(result == null || result.length < 1){
        return "";
    }
    return result[1];
}
};
